<template>
  <div class="cartcontrol">
    <transition>
      <div class="cart-decrease" v-show="food.count > 0" @click.stop.prevent="decreaseCart">
        <span class="inner icon-thumb_down"></span>
      </div>
    </transition>
    <div class="cart-count" v-show="food.count > 0">{{food.count}}</div>
    <div class="cart-add icon-add_circle" @click.stop.prevent="addCart"></div>
  </div>
</template>

<script>
import Vue from 'vue'
import { mapState, mapMutations, mapActions, mapGetters } from 'vuex'

export default {
  name: 'CartControl',
  props: {
    food: Object
  },
  methods: {
    ...mapMutations(['SET_COUNT', 'DEC_COUNT', 'DROP']),
    addCart () {
      this.SET_COUNT({food: this.food})
      this.DROP(event.target)
    },
    decreaseCart () {
      this.DEC_COUNT({food: this.food})
    }
  }
}
</script>

<style lang="stylus" scoped>
.cartcontrol
  .cart-decrease
    float left
    padding 6px
    .inner
      line-height 24px
      font-size 24px
      color rgb(0,160,220)
    &.v-enter-active, &.v-leave-active
      transition all 0.5s linear
      opacity 1
      transform translate3d(0,0,0)
      .inner
        transition all 0.5s
        opacity 1
        transform rotate(0deg)
    &.v-enter, &.v-leave-active
      opacity 0
      transform translate3d(24px, 0, 0)
      .inner
        opacity 0
          transform rotate(180deg)
  .cart-count
    float left
    width 12px
    line-height 24px
    margin-top 5px
    font-size 12px
    text-align center
    color rgb(147,153,159)
  .cart-add
    float left
    padding 6px
    line-height 24px
    font-size 24px
    color rgb(0,160,220)
</style>
